﻿using System;
using System.Diagnostics.Contracts;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Reflection;

namespace CodePlex.Diagnostics.Contracts
{
	[Serializable]
	public class ContractValidationException
		: Exception
	{
		public ContractValidationException()
		{ }

		public ContractValidationException(string message)
			: base(message)
		{ }

		protected ContractValidationException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
      this.Property = (PropertyInfo)info.GetValue("Property", typeof(PropertyInfo));
    }

		public ContractValidationException(string message, Exception innerException)
			: base(message, innerException)
		{
		}

    public ContractValidationException(PropertyInfo property, Exception innerException)
      : base(null, innerException)
    {
      this.Property = property;
    }

    [SecurityCritical, SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
    public override void GetObjectData(SerializationInfo info, StreamingContext context)
    {
      base.GetObjectData(info, context);
      info.AddValue("Property", this.Property);
    }

    public PropertyInfo Property { get; private set; }
  }
}
